package com.sunwayworld.basemodule.common.eptstorage.db.service.impl;

import com.sunwayworld.basemodule.common.eptstorage.db.bean.LimsDbextractBean;
import com.sunwayworld.basemodule.common.eptstorage.db.dao.LimsDbextractDao;
import com.sunwayworld.basemodule.common.eptstorage.db.service.LimsDbextractService;
import com.sunwayworld.framework.at.annotation.AuditTrailEntry;
import com.sunwayworld.framework.at.annotation.AuditTrailType;
import com.sunwayworld.framework.context.ApplicationContextHelper;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@GikamBean
public class LimsDbextractServiceImpl implements LimsDbextractService {

    @Autowired
    private LimsDbextractDao limsDbextractDao;

    @Override
    @SuppressWarnings("unchecked")
    public LimsDbextractDao getDao() {
        return limsDbextractDao;
    }

    @Override
    @Transactional
    @AuditTrailEntry(AuditTrailType.INSERT)
    public Long insert(RestJsonWrapperBean jsonWrapper) {
        LimsDbextractBean limsDbextract = jsonWrapper.parseUnique(LimsDbextractBean.class);
        limsDbextract.setId(ApplicationContextHelper.getNextIdentity());
        getDao().insert(limsDbextract);
        return limsDbextract.getId();
    }

}
